﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;
using System.Text;
using Dapper.Contrib.Extensions;
using DapperExtensions.Mapper;

namespace MaximServices.Model
{
    [Dapper.Contrib.Extensions.Table("motto_rule")]
    public class MottoRule
    {
        [Key]
        [Column("id")]
        public string Id { get; set; }

        [Column("startdate")]
        public DateTime? StartDate { get; set; }

        [Column("enddate")]
        public DateTime? EndDate { get; set; }

        [Column("rule_name")]
        public string Rule_Name { get; set; }

        [Column("rule_json")]
        public string Rule_Json { get; set; }

        [Column("usedefault_rule")]
        public int Usedefault_Rule { get; set; }

        [Column("sort_order")]
        public int Sort_Order { get; set; }

        [Column("create_time")]
        public DateTime Create_Time { get; set; }

        [Column("modify_time")]
        public DateTime Modify_Time { get; set; }
    }

    public class MottoRuleMapper : ClassMapper<MottoRule>
    {
        public MottoRuleMapper()
        {
            //use different table name
            Table("motto_rule");

            //use a custom schema
            Schema("");

            //have a custom primary key
            Map(x => x.Id).Column("id").Key(KeyType.Assigned);

            Map(x => x.StartDate).Column("startdate");
            Map(x => x.EndDate).Column("enddate");
            Map(x => x.Rule_Name).Column("rule_name");
            Map(x => x.Rule_Json).Column("rule_json");
            Map(x => x.Usedefault_Rule).Column("usedefault_rule");
            Map(x => x.Sort_Order).Column("sort_order");
            Map(x => x.Create_Time).Column("create_time");
            Map(x => x.Modify_Time).Column("modify_time");

            AutoMap();
            //optional, map all other columns
        }
    }
}
